package kr.hkit.powerjava.chapter26.main;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Scanner;

import kr.hkit.powerjava.chapter26.common.ConnectionFactory;
import kr.hkit.powerjava.chapter26.common.DbUtil;
import kr.hkit.powerjava.chapter26.dao.DepartmentDAO;
import kr.hkit.powerjava.chapter26.dto.Department;
import kr.hkit.powerjava.chapter26.dto.Employee;
import kr.hkit.powerjava.chapter26.service.AbsService;
import kr.hkit.powerjava.chapter26.service.DepartmentService;
import kr.hkit.powerjava.chapter26.service.EmployeeService;

public class TestMain {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Connection connection = ConnectionFactory.getConnection();
		boolean flag = true;
		int res = 0;
		while(flag) {
			System.out.println("1.학과정보\n2.부서정보\n3.종료");
			res = sc.nextInt();
			switch(res) {
				case 1:
					System.out.println("**********학과정보**********");
					AbsService<Department> deptSvc = new DepartmentService(sc, connection);
					deptSvc.prnMenu();
					break;
				case 2:
					System.out.println("**********부서정보**********");
					AbsService<Employee> empSvc = new EmployeeService(sc, connection);
					empSvc.prnMenu();
					break;
				default:
					flag = false;
					DbUtil.close(connection);
					sc.close();
					System.exit(0);
			}
		}
		
//		Department 학
//		AbsService<Department> deptSvc = new DepartmentService(sc, connection);
//		deptSvc.prnMenu();

//		AbsService<Employee> empSvc = new EmployeeService(sc, connection);
//		empSvc.prnMenu();
		
		
		//끝날 때 종료되게 하기
		//DbUtil.close(connection);
		
		//부서
		
		
		//employee가 되도록 하기
		
		
		
//		DepartmentDAO dao = null; //new DepartmentDAO();
//		Department d = new Department(6, "마케팅", 8);
		
/*		try {
			ArrayList<Department> list = dao.listItems();
			for(Department dept : list) {
				System.out.println(dept);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}*/
		
/*		try {
			dao.insertItem(d);
			System.out.println("삽입 성공!");
		} catch (SQLException e) {
			System.err.println(e.getMessage() + " : " + e.getErrorCode());
		}*/
		
/*		try {
			dao.deleteItembyNo(new Department(6));
			System.out.println("삭제 성공!");
		} catch (SQLException e) {
			System.err.println(e.getMessage() + " : " + e.getErrorCode());
		}*/
		
/*		try {
			d.setDeptName("교육");
			dao.updateItembyNo(d);
			System.out.println("수정 성공!" + d);
		} catch (SQLException e) {
			System.err.println(e.getMessage() + " : " + e.getErrorCode());
		}*/
		
//		Connection con = ConnectionFactory.getConnection();
//		System.out.println(con);
		//ConnectionFactory에서 getConnection()에 접근 가능!
//		DBProperties.prnProperties(prop);
		
/*		String driver = "com.mysql.jdbc.Driver";
		String url = "jdbc:mysql://localhost:3306/mysql_study";
		String user = "root";
		String password = "1111";
		
		DBProperties.savePropertis("dbcon.xml", driver, url, user, password);
		*/
	}
	/*public static void xmlLoad() {
		Properties prop = DBProperties.loadPropertis("dbcon.xml");
		if(prop != null) {
			System.out.println("데이터 있습니다.");
		}
	}*/
}